#!/bin/bash

DIRECTORY="$(dirname "$(dirname "$( cd "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )")")"

function error {
  echo -e "\\e[91m$1\\e[39m"
  exit 1
}
# Get dependencies
"${DIRECTORY}/pkg-install" "build-essential qmlscene qt5-qmake qt5-default qtdeclarative5-dev qml-module-qtquick-controls qml-module-qtgraphicaleffects qml-module-qtquick-dialogs qml-module-qtquick-localstorage qml-module-qtquick-window2 qml-module-qt-labs-settings qml-module-qt-labs-folderlistmodel" "$(dirname "$0")" || exit 1

# Remove cool-retro-term folder first
rm -rf cool-retro-term || sudo rm -rf cool-retro-term 

# Get CRT from github
git clone --recursive https://github.com/Swordfish90/cool-retro-term || error "failed to clone repository!"

# Compile
cd cool-retro-term || error "failed on cd step!"
qmake || error "failed on qmake step!"
make -j8 || error "failed on make step!"

cp -rf qmltermwidget/src/qmldir qmltermwidget/lib/kb-layouts qmltermwidget/lib/color-schemes qmltermwidget/src/QMLTermScrollbar.qml qmltermwidget/QMLTermWidget

echo "[Desktop Entry]
Comment=Use the command line the old way
Exec=$HOME/cool-retro-term/cool-retro-term
GenericName=Terminal emulator
Icon=$HOME/cool-retro-term/app/icons/64x64/cool-retro-term.png
Name=Cool Retro Term
Categories=GTK;System;TerminalEmulator;
StartupNotify=true
Terminal=false
Type=Application
Keywords=shell;prompt;command;commandline;console;command line;execute;" > ~/.local/share/applications/crt.desktop
